package com.jiyoukeji.template.exception;

import com.jiyoukeji.template.utils.Result;
import org.apache.ibatis.jdbc.Null;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: 李培洋
 * @Date: 2024/11/20 23:25
 * @Description: 全局异常处理类
 */
@RestControllerAdvice
public class GlobalExceptionHandle {

    /**
     * @Author: 李培洋
     * @Date: 2024/11/20 23:25
     * @Description: 全局异常处理实现
     */
    @ExceptionHandler(Exception.class)
    public Result<Null> handleException(Exception e) {
        return Result.fail(StringUtils.hasLength(e.getMessage()) ? e.getMessage() : "操作失败");
    }
}
